
<?php
include("db/connect.php");
$dlt="delete from cartmaterial where ordermat_id=0";
$querydlt=mysql_query($dlt);
$selectmaterial="SELECT * FROM material ORDER BY mat_name ASC";
$selectmaterial="select * from material where mat_id='".$_POST["temp"]."'";
$querymaterial=mysql_query($selectmaterial);
$querymaterial=mysql_query($selectmaterial);
$resultmaterial=mysql_fetch_array($querymaterial);
?>

<script>
	function submitMat(){
	//console.log($("#fromInsert_Add_Pro").serialize()+"&mat_id="+$("#mat_id").val());
	if($("#mat_qty").val()>=1){
		console.log($("#fromInsert_Add_Mat").serialize()+"&mat_id="+$("#mat_id").val());
	$.ajax({
			type:"POST",
			url:"shoppingcartmaterial2.php",
			data:$("#fromInsert_Add_Mat").serialize()+"&mat_id="+$("#mat_id").val(),
			success:function(msg){
		console.log(msg);
		if(msg!=1)
	{$("#spantest").html(msg);selectcartmaterial();}
	}
			});//ajax
	}
	else{
		alert("จำนวนไม่ถูกต้อง");
		}
	}//function submit   
	function dltcartmaterial(PID,mode){
	if(window.confirm("ท่านต้องลบใช่หรือไม่")){
	$.ajax({
	url:"dltcartmaterial.php",
	data:"PID="+PID+"&mode="+mode,
	type:"POST",
	success:function(msg){
	alert(msg);
	if(mode=="all"){ajaxlist();}else{selectcartmaterial();}
	}
	});}
	}

	function selectcartmaterial(){
	$.ajax({
	url:"shoppingcartmaterial3.php",
	success:function(msg){
	$("#spantest").html(msg);
	}
	});
	}
	function agreecartmaterial(){
	$.ajax({
	url:"agreecartmaterial.php",
	type:"POST",
	data:"mat_id="+$("#mat_id").val(),
	success:function(msg){
		
	if(msg!=1)
	{$("#spantest").html(msg);selectcartmaterial();}
	else 
	alert("มีรายการเดิมที่ยังไม่เสร็จสมบูรณ์");
	
	}
	});
	}
</script>

<style type="text/css">
#fromInsert_Add_Mat p {
	text-align: center;
	font-size: 36px;
}
</style>


<form id="fromInsert_Add_Mat" name="fromInsert_Add_Mat" method="post" action="Javascript:submitMat();">
  <p>ข้อมูลการสั่งซื้อสินค้า</p>
 
  <table width="528" border="0">
    <tr>
      <td>ชื่อวัตถุดิบ</td>
      <td>
      <input type="hidden" name="mat_id" id="mat_id" disabled="disabled" value="<?php echo $resultmaterial["mat_id"]?>" />
      <input type="text" name="mat_name" id="mat_name" disabled="disabled" value="<?php echo $resultmaterial["mat_name"]?>" /></td>
    </tr>
    <tr>
      <td>จำนวน</td>
      <td><input type="number" name="mat_qty" id="mat_qty" /></td>
    </tr>
  </table>
  <p>
    <input type="submit" name="button3" id="button3" value="เพิ่มรายการ" />
    <input type="button" name="btnagree" id="btnagree" value="ยืนยัน" onclick="Javascript:agreecartmaterial();" />
    <input type="button" name="button2" id="button2" value="ยกเลิก"  onclick="Javascript:dltcartmaterial('','all');" />
  </p>
  <p>&nbsp;</p>
</form>
<div id="spantest"></div>

